﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace NKD07.Classes
{
    public class manufacturer:database
    {
        private int id;
        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string address;
        public string Address
        {
            get { return address; }
            set { address = value; }
        }

        private string city;
        public string City
        {
            get { return city; }
            set { city = value; }
        }

        private string phone;
        public string Phone
        {
            get { return phone; }
            set { phone = value; }
        }

        private string email;
        public string Email
        {
            get { return email; }
            set { email = value; }
        }

        private string username;
        public string Username
        {
            get { return username; }
            set { username = value; }
        }

        private string password;
        public string Password
        {
            get { return password; }
            set { password = value; }
        }

        private string usernamAccess;
        public string UsernamAccess
        {
            get { return usernamAccess; }
            set { usernamAccess = value; }
        }

        private string passwordAccess;
        public string PasswordAccess
        {
            get { return passwordAccess; }
            set { passwordAccess = value; }
        }

        // get all manuafacturer from database
        public DataTable getAllManufacturer()
        {
            DataTable categories = new DataTable();
            OpenConnection();
            if (Connection != null)
            {
                string queryString = "select * from Manufacturer";
                try
                {
                    SqlDataAdapter adapter = new SqlDataAdapter(queryString, Connection);
                    adapter.Fill(categories);
                }
                catch (SqlException)
                {
                    categories = new DataTable();
                }
            }
            CloseConnection();
            return categories;
        }

        public DataTable GetManufacturerByID(int manufacturerID)
        {
            DataTable product = new DataTable();
            OpenConnection();
            if (Connection != null)
            {
                string queryString = "select * from Manufacturer m where  m.id=" + manufacturerID.ToString();
                try
                {
                    SqlDataAdapter adapter = new SqlDataAdapter(queryString, Connection);
                    adapter.Fill(product);
                }
                catch (SqlException)
                {
                    product = new DataTable();
                }
            }
            return product;
        }

    }
}